//
//  SettingViewController.m
//  CouponManager
//
//  Created by BoHyun Jo on 11. 5. 18..
//  Copyright 2011 CJ오쇼핑. All rights reserved.
//

#import "SettingViewController.h"
#import "CMPasswordViewController.h"

#import "Const.h"
@implementation SettingViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [pwSetting release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    if([prefs integerForKey:@"isPassword"]){
        [pwSetting setTitle:@"패스워드 켜짐" forState:0];
    }else{
        [pwSetting setTitle:@"패스워드 꺼짐" forState:0];
        
    }
    
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - IBAction
-(IBAction)pwChange:(id)sender{
    CMPasswordViewController* passwordViewController = [[CMPasswordViewController alloc] initWithNibName:@"CMPasswordViewController" bundle:nil];
    [passwordViewController setState:PASS_SETUP];
    [self presentModalViewController:passwordViewController animated:NO];
    
}
-(IBAction)pwSetting:(id)sender{
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    if(![prefs integerForKey:@"isPassword"]){
        [(UIButton*)sender setTitle:@"패스워드 켜짐" forState:0];
        CMPasswordViewController* passwordViewController = [[CMPasswordViewController alloc] initWithNibName:@"CMPasswordViewController" bundle:nil];
        [passwordViewController setState:PASS_SETUP];
        [self presentModalViewController:passwordViewController animated:NO];
    }else{
        
        [prefs setInteger:0 forKey:@"isPassword"];     
 //       [prefs setInteger:![prefs integerForKey:@"isPassword"] forKey:@"isPassword"];
        [(UIButton*)sender setTitle:@"패스워드 꺼짐" forState:0];
        
    }
    /*
    CMPasswordViewController* passwordViewController = [[CMPasswordViewController alloc] initWithNibName:@"CMPasswordViewController" bundle:nil];
    [self presentModalViewController:passwordViewController animated:YES];
     */
    
    
}

@end
